package ch.fusun.baron.unit.service;

import java.util.Collection;
import java.util.Map;

import ch.fusun.baron.core.injection.Inject;
import ch.fusun.baron.data.DataUpdate;
import ch.fusun.baron.map.Tile;
import ch.fusun.baron.unit.Unit;

/**
 * Updates the {@link UnitService}
 */
public class UnitDataUpdate implements DataUpdate {

	private Map<Tile, Collection<Unit>> tileUnitMap;
	private int index;

	@Inject
	private transient UnitService unitService;

	/**
	 * Don't use
	 */
	public UnitDataUpdate() {
	}

	/**
	 * Constructor
	 * 
	 * @param tileUnitMap
	 *            The mapping from tiles to units on the tile
	 */
	public UnitDataUpdate(Map<Tile, Collection<Unit>> tileUnitMap, int index) {
		this.tileUnitMap = tileUnitMap;
		this.index = index;
	}

	@Override
	public void update() {
		unitService.setUnitMap(tileUnitMap);
		unitService.setIndex(index);
	}
}
